<!--
 * @Description: 寝室视频列表 - 学生上传 - 查看批次组详情
 * @Author: liyujie
 * @Date: 2021/3/15
 * @Last Modified by: liyujie
 * @Last Modified time: 2021/3/15
-->
<template>
    <div class="wrapper">
        <div class="content-wrapper">
            <!-- 筛选-->
            <el-tabs
                v-model="filterData.type"
                v-if="!filterData.series_no"
                @tab-click="getTableData(1)"
            >
                <el-tab-pane
                    label="用户上传"
                    name="2"
                />
                <el-tab-pane
                    label="平台上传"
                    name="1"
                />
            </el-tabs>
            <div class="filter-view">
                <div class="header-new-box">
                    <p class="header-new-box-title">
                        公司名称
                    </p>
                    <el-input
                        v-model="filterData.company_name"
                        size="medium"
                        placeholder="请输入公司名称"
                        clearable
                        @keydown.enter.native="getTableData(1)"
                    />
                    <!--<el-select
                        v-model="filterData.company_name"
                        filterable
                        remote
                        clearable
                        size="medium"
                        reserve-keyword
                        placeholder="请输入公司名称"
                        :remote-method="remoteMethod"
                        @change="handleCompanyChange"
                    >
                        <el-option
                            v-for="item in suggestList"
                            :key="item.hire_no"
                            :label="item.company_name"
                            :value="item.company_name"
                        />
                    </el-select>-->
                </div>
                <div class="header-new-box">
                    <p class="header-new-box-title">
                        产品名称
                    </p>
                    <el-input
                        placeholder="请输入产品名称"
                        v-model="filterData.series_title"
                        suffix-icon="el-icon-search"
                        clearable
                        size="medium"
                        @keydown.enter.native="getTableData(1)"
                    />
                </div>
                <div class="header-new-box">
                    <p class="header-new-box-title">
                        视频批次
                    </p>
                    <el-select
                        v-model="filterData.series_index"
                        clearable
                        filterable
                        placeholder="全部"
                        size="medium"
                        style="width: 152px"
                        @change="getTableData(1)"
                    >
                        <el-option
                            v-for="item in seriesList"
                            :key="item.series_index"
                            :label="item.series_index"
                            :value="item.series_index"
                        />
                    </el-select>
                </div>
                <div class="header-new-box">
                    <p class="header-new-box-title">
                        寝室性别
                    </p>
                    <el-select
                        v-model="filterData.sex"
                        placeholder="不限"
                        size="medium"
                        style="width: 152px"
                        @change="getTableData(1)"
                    >
                        <el-option
                            v-for="item in sexList"
                            :key="item.value"
                            :label="item.label"
                            :value="item.value"
                        />
                    </el-select>
                </div>

                <div class="header-new-box">
                    <el-button
                        type="primary"
                        size="small"
                        @click="getTableData(1)"
                    >
                        查询
                    </el-button>
                </div>
            </div>
            <!--筛选-->

            <!-- table -->
            <el-table
                :data="tableData"
                height="100%"
                style="width: 100%;"
                ref="tempLateName"
                class="data-table"
                v-loading="tableLoading"
            >
                <el-table-column
                    label="序号"
                    align="center"
                    width="80"
                    type="index"
                />
                <el-table-column
                    prop="company_name"
                    label="公司名称"
                    show-overflow-tooltip
                    align="left"
                    :formatter="emptyFormatter"
                />
                <el-table-column
                    prop="series_title"
                    label="产品名称"
                    show-overflow-tooltip
                    align="left"
                    :formatter="emptyFormatter"
                />
                <el-table-column
                    prop="series_index"
                    label="批次"
                    show-overflow-tooltip
                    align="center"
                />
                <template v-if="!filterData.series_no">
                    <el-table-column
                        prop="school_name"
                        label="学校"
                        show-overflow-tooltip
                        align="center"
                    />
                    <el-table-column
                        prop="title"
                        label="所属批次组"
                        show-overflow-tooltip
                        width="110"
                        align="center"
                    />
                </template>
                <el-table-column
                    label="寝室性别"
                    show-overflow-tooltip
                    align="center"
                    :formatter="emptyFormatter"
                >
                    <template slot-scope="scope">
                        {{ scope.row.sex === 1 ? '男' : scope.row.sex === 2 ? '女' : '不限' }}
                    </template>
                </el-table-column>
                <el-table-column
                    label="最近提交时间"
                    align="center"
                    width="200"
                    :formatter="emptyFormatter"
                >
                    <template slot-scope="scope">
                        {{ scope.row.submit_audit_time * 1000 | dateFormatter('yyyy/MM/dd HH:mm:ss') }}
                    </template>
                </el-table-column>
                <template v-if="filterData.type === '2'">
                    <el-table-column
                        prop="student_appoint_count"
                        key="student_appoint_count"
                        label="委派人数"
                        show-overflow-tooltip
                        align="center"
                    />
                    <el-table-column
                        prop="video_student_audit_pass_count"
                        key="video_student_audit_pass_count"
                        show-overflow-tooltip
                        align="center"
                        :formatter="emptyFormatter"
                        width="150"
                        :render-header="(h, title, content) => renderHeader(h, '有效数量/目标数量', '有效数量指的是运营审核通过的数量，目标数量指的是，运营创建批次的时候给用户定的目标数量。')"
                    >
                        <template slot-scope="scope">
                            {{ scope.row.video_student_audit_pass_count }} / {{ scope.row.count }}
                        </template>

                    </el-table-column>
                    <el-table-column
                        prop="video_student_audit_wait_count"
                        key="video_student_audit_wait_count"
                        show-overflow-tooltip
                        align="center"
                        :render-header="(h, title, content) => renderHeader(h, '待审核数', '用户上传视频且提交了审核，总后台未进行审核的数量')"
                    />
                    <el-table-column
                        prop="video_student_audit_fail_count"
                        key="video_student_audit_fail_count"
                        show-overflow-tooltip
                        align="center"
                        :render-header="(h, title, content) => renderHeader(h, '未通过数', '用户提交审核，未通过的数量')"
                    />
                    <el-table-column
                        prop="video_student_audit_submit_count"
                        key="video_student_audit_submit_count"
                        show-overflow-tooltip
                        align="center"
                        :render-header="(h, title, content) => renderHeader(h, '提交总数', '用户上传视频且提交审核的数量之和')"
                    />
                    <el-table-column
                        prop="video_score"
                        key="video_score"
                        show-overflow-tooltip
                        align="center"
                        :render-header="(h, title, content) => renderHeader(h, '总分数', '审核通过的视频分数之和，且是所有人的总分之和')"
                    />
                </template>
                <template v-if="filterData.type === '1'">
                    <el-table-column
                        prop="video_audit_wait_count"
                        label="待审核数"
                        key="video_audit_wait_count"
                        show-overflow-tooltip
                        align="center"
                    />
                    <el-table-column
                        prop="video_audit_fail_count"
                        label="未通过数"
                        key="video_audit_fail_count"
                        show-overflow-tooltip
                        align="center"
                    />
                    <el-table-column
                        prop="video_audit_pass_count"
                        label="已通过数"
                        key="video_audit_pass_count"
                        show-overflow-tooltip
                        align="center"
                    />
                    <el-table-column
                        prop="video_count"
                        label="视频总数"
                        key="video_count"
                        show-overflow-tooltip
                        align="center"
                        :width="110"
                    />
                    <el-table-column
                        prop="video_submit_count"
                        align="center"
                        key="video_submit_count"
                        label="可提审"
                        show-overflow-tooltip
                    />
                </template>
                <el-table-column
                    label="操作"
                    align="center"
                >
                    <template slot-scope="scope">
                        <el-button
                            type="text"
                            size="medium"
                            @click="toVideoDetail(scope.row)"
                        >
                            查看视频
                        </el-button>
                    </template>
                </el-table-column>
            </el-table>
            <!-- /table -->

            <!-- /分页 -->
            <div class="pagination-wrapper clearfix">
                <el-pagination
                    layout="total, prev, pager, next, jumper"
                    background
                    :current-page.sync="page.now_page"
                    :total="page.total_count"
                    :page-size="page.page_size"
                    @current-change="getTableData"
                />
            </div>
        </div>
    </div>
</template>

<script>
import { back } from '@/mixin/back';

export default {
    name: 'StudentVideoList',
    mixins: [back],
    components: {},
    data() {
        return {
            filterData: {
                series_no: '',
                type: '2',
                // 公司名称
                company_name: '',
                // 批次
                series_index: '',
                // 产品名称
                series_title: '',
                // 性别
                sex: 99,
            },
            tableData: [],
            tableLoading: false,
            page: {
                now_page: 1,
                total_count: 0,
                page_size: 20
            },
            dateTimeRange: [],
            // 性别
            sexList: [
                {label: '全部', value: 99},
                {label: '不限', value: 0},
                {label: '男', value: 1},
                {label: '女', value: 2},
            ],
            // 视频批次列表
            seriesList: [],
            suggestList: []
        };
    },
    computed: {},
    watch: {},

    mounted() {
        let query = this.$route.query;

        this.$store.commit('SET_HEADER', [{title: "官网"}, {title: '商家增值服务'}, {title: '寝室视频上传'}, {title: '批次组', path: '/bid/dorm-video-list'}, {title: '查看详情'}]);
        this.authResult = this.$route.meta.authResult;
        this.filterData.series_no = query.no;
        this.getSuggest();
        this.getSeriesList();
        this.getTableData();
    },

    methods: {

        /**
         * @description 获取列表数据
         * @param page
         */
        getTableData(page) {
            this.tableLoading = true;
            let params = { ...this.filterData };

            params.page_id = page || this.page.now_page;
            this.$post('/student/room_series%5Cget_link_hire_list', params, res => {
                if (res.code === 1) {
                    this.tableData = res.data.list;
                    this.page = res.data.page;
                }
                this.tableLoading = false;
            });
        },

        /**
         * @description 过滤函数
         */
        emptyFormatter(row, column, val) {
            if (!val) return '--';
            return val;
        },

        /**
         * 自定义表格标题hover提示
         */
        renderHeader(h,title, content){
            return h('span', {}, [
                h('span', {}, title),
                h('el-popover', { props: { placement: 'top-start', width: '200', trigger: 'hover', content: content }}, [
                    h('i', { slot: 'reference', class:'el-icon-question', style: 'color:#666'}, '')
                ])
            ]);
        },

        /**
         * 路由跳转
         * @param routeName
         * @param query
         */
        handleRoute(routeName, query) {
            this.$router.push({
                name: routeName,
                query
            });
        },

        /**
         * @description 搜索公司名称
         */
        remoteMethod (query) {
            if (query !== '') {
                setTimeout(() => {
                    this.getSuggest(query);
                }, 200);
            }
        },

        /**
         * @description 获取商家列表
         */
        getSuggest (keyword) {
            this.$post('/student/room_series%5Cget_company_list', {
                keyword: keyword
            }, resp => {
                if (resp.code === 1) {
                    this.suggestList = resp.data.list;
                }
            });
        },

        /**
         * @description 获取视频批次列表/视频批次搜索
         */
        getSeriesList () {
            this.$post('/student/room_series%5Cget_series_index_list', {
                type: 2,
                keyword: '',
                hire_no: this.filterData.hire_no,
                is_audit: ''
            }, resp => {
                if (resp.code === 1) {
                    this.seriesList = resp.data.list;
                }
            });
        },

        /**
         * 选择公司发生变化
         */
        handleCompanyChange() {
            this.getSeriesList();
            this.getTableData(1);
        },

        /**
         * 跳转详情
         * @param row
         */
        toVideoDetail(row) {
            let query = row.type === 1 ? {series_no: row.series_no} : {no: row.series_no};

            this.handleRoute(`${row.type === 1 ? 'dormVideoUpload' : 'studentVideoDetail'}`, query);
        }

    }
};
</script>

<style lang="less" scoped>
.wrapper {
    width: 100%;
    flex: 1;
    /*el-tabs*/

    /deep/ .el-tabs {
        .el-tabs__nav-wrap {
            height: 54px;
            padding-left: 24px;
            .el-tabs__nav-scroll {
                .el-tabs__nav {
                    height: 54px;
                    line-height: 54px;
                }
            }
        }
        .el-tabs__header {
            margin: 0;
        }
    }

    .content-wrapper {
        display: flex;
        height: calc(100% - 24px);
        flex-direction: column;
        position: relative;
        width: calc(100% - 24px);
        margin: 12px;
        padding: 0 24px;
        background: #fff;
        box-sizing: border-box;

        /*header*/

        .header {
            box-sizing: border-box;
            display: flex;
            align-items: center;
            justify-content: space-between;
            border-bottom: 1px solid #F0F2F5;

            .header-title {
                color: #333333;
                font-size: 20px;
                height: 20px;
                font-weight: 500;
                position: relative;
                margin-left: 12px;
                margin-bottom: 24px;

                &::before {
                    content: '';
                    position: absolute;
                    left: -8px;
                    top: -1px;
                    width: 3px;
                    height: 20px;
                    background: #1890FF;
                }
            }
        }

        /*筛选*/

        .filter-view {
            margin-top: 24px;
            box-sizing: border-box;
            display: flex;
            align-items: center;
            flex-wrap: wrap;

            .header-new-box {
                display: flex;
                align-items: center;
                font-family: PingFangSC-Regular, PingFang SC;
                font-weight: 400;
                color: #333333;
                white-space: nowrap;
                margin-right: 24px;
                margin-bottom: 24px;

                &-title {
                    margin-right: 16px;
                    white-space: nowrap;
                }
            }
        }

        // 表格
        .data-table {
            ::-webkit-scrollbar {
                width: 6px;
                height: 6px;
            }
            // 操作按钮
            .option-btn-group {
                .el-button {
                    margin-left: 0;
                    margin-right: 10px;
                }
            }
        }
        /* 分页 */

        .pagination-wrapper {
            padding: 10px;
            .el-pagination {
                float: right;
                padding: 0;
                background-color: transparent;
            }
        }
    }
    /deep/ .el-dialog__header {
        padding-top: 10px;
        box-shadow:0 1px 0 0 rgba(233,233,233,1);
        display: flex;
        align-items: center;
        background: #FAFAFA;
        border-radius: 4px 4px 0 0;
        .el-dialog__title {
            font-weight: 500;
            color: #333;
            font-size: 14px;
        }
        .el-icon-close:before {
            color: rgb(194,194,194);
            font-size: 17px;
            font-weight: bold;
        }
        .el-dialog__headerbtn {
            top: 14px;
        }
    }
}
</style>

